package com.lmiot.xyclick.Bind;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.internal.view.SupportMenu;
import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.lmiot.xyclick.Util.SpFlag;
import com.bumptech.glide.Glide;
import com.lkx.liandianqinew.R;
import com.lmiot.floatviewsdklibrary.SDK.YYFloatButton;
import com.lmiot.xyclick.Activity.WebViewActivity;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.InitFloatBean;
import com.lmiot.xyclick.Bean.SQL.ActionBean;
import com.lmiot.xyclick.Notic.NoticEnum;
import com.lmiot.xyclick.Notic.NoticManager;
import com.lmiot.xyclick.Util.ActivityUtil;
import com.lmiot.xyclick.Util.ClickUtils;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.FloatManager;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.MathUtils;
import com.lmiot.xyclick.Util.SpFlag;
import com.yhao.floatwindow.FloatUtil;
import com.youyi.yyviewsdklibrary.ArrayGson;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.View.MyListView;
import com.youyi.yyviewsdklibrary.View.TitleBarView;

public class FloatFragment extends Fragment implements View.OnClickListener {
    private BindEnum[] mBindEnums;
    private Context mContext;
    private Dialog mDialog;
    private FlaotAdapter mFlaotAdapter;
    LinearLayout mIdFloatClickLayout;
    LinearLayout mIdFloatClickLayoutPlus;
    SwitchCompat mIdFloatClickSwitch;
    SwitchCompat mIdFloatClickSwitchPlus;
    ImageView mIdFloatImg;
    LinearLayout mIdFloatLayout;
    MyListView mIdFloatListview;
    SwitchCompat mIdFloatSwitch;
    TextView mIdHelp;
    ImageView mIdImg;
    ImageView mIdImgPlus;
    TitleBarView mIdTitleBar;
    LinearLayout mIdTrackClickLayout;
    SwitchCompat mIdTrackClickSwitch;
    private Intent mIntent;

    public FloatFragment() {
    }

    public FloatFragment(Context context) {
        this.mContext = context;
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_float, (ViewGroup) null);
        this.mIdTitleBar = (TitleBarView) inflate.findViewById(R.id.id_title_bar);
        this.mIdHelp = (TextView) inflate.findViewById(R.id.id_help);
        this.mIdFloatImg = (ImageView) inflate.findViewById(R.id.id_float_img);
        this.mIdFloatSwitch = (SwitchCompat) inflate.findViewById(R.id.id_float_switch);
        this.mIdFloatLayout = (LinearLayout) inflate.findViewById(R.id.id_float_layout);
        this.mIdImg = (ImageView) inflate.findViewById(R.id.id_img);
        this.mIdFloatClickSwitch = (SwitchCompat) inflate.findViewById(R.id.id_float_click_switch);
        this.mIdFloatClickLayout = (LinearLayout) inflate.findViewById(R.id.id_float_click_layout);
        this.mIdImgPlus = (ImageView) inflate.findViewById(R.id.id_img_plus);
        this.mIdFloatClickSwitchPlus = (SwitchCompat) inflate.findViewById(R.id.id_float_click_switch_plus);
        this.mIdFloatClickLayoutPlus = (LinearLayout) inflate.findViewById(R.id.id_float_click_layout_plus);
        this.mIdTrackClickSwitch = (SwitchCompat) inflate.findViewById(R.id.id_track_click_switch);
        this.mIdTrackClickLayout = (LinearLayout) inflate.findViewById(R.id.id_track_click_layout);
        this.mIdFloatListview = (MyListView) inflate.findViewById(R.id.id_float_listview);
        this.mIdHelp.setOnClickListener(this);
        this.mIdFloatSwitch.setOnClickListener(this);
        this.mIdFloatLayout.setOnClickListener(this);
        this.mIdFloatClickSwitch.setOnClickListener(this);
        this.mIdFloatClickLayout.setOnClickListener(this);
        this.mIdFloatClickSwitchPlus.setOnClickListener(this);
        this.mIdFloatClickLayoutPlus.setOnClickListener(this);
        this.mIdTrackClickSwitch.setOnClickListener(this);
        this.mIdTrackClickLayout.setOnClickListener(this);
        setTitle();
        return inflate;
    }

    private void setTitle() {
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            /* class com.lmiot.xyclick.Bind.FloatFragment.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
                ActivityUtil.skipActivity(FloatFragment.this.mContext, FloatSettingActivity.class);
            }
        });
    }

    @Override // android.support.v4.app.Fragment
    public void onResume() {
        super.onResume();
        setColor();
        this.mIdFloatSwitch.setChecked(FloatUtil.getShowFlow(this.mContext));
        this.mIdFloatClickSwitch.setChecked(FloatUtil.getShowFlowClick(this.mContext));
        this.mIdTrackClickSwitch.setChecked(FloatUtil.getShowTrackClick(this.mContext));
        setFloatListView();
        boolean z = false;
        this.mIdFloatListview.setFocusable(false);
        int i = 0;
        while (true) {
            if (i >= 10) {
                break;
            } else if (FloatUtil.getShowFlowClickPlus(MyApp.getContext(), i)) {
                z = true;
                break;
            } else {
                i++;
            }
        }
        this.mIdFloatClickSwitchPlus.setChecked(z);
    }

    private void setColor() {
        switch (YYFloatButton.getFloatViewColor(this.mContext)) {
            case 1:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor1));
                return;
            case 2:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor2));
                return;
            case 3:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor3));
                return;
            case 4:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor4));
                return;
            case 5:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor5));
                return;
            case 6:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor6));
                return;
            case 7:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.fcolor7));
                return;
            case 8:
                this.mIdFloatImg.setColorFilter(getResources().getColor(R.color.translate));
                return;
            default:
                return;
        }
    }

    private void setFloatListView() {
        this.mBindEnums = BindEnum.values();
        FlaotAdapter flaotAdapter = new FlaotAdapter();
        this.mFlaotAdapter = flaotAdapter;
        this.mIdFloatListview.setAdapter((ListAdapter) flaotAdapter);
    }

    @Override // android.support.v4.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.id_float_click_layout /*{ENCODED_INT: 2131296645}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    return;
                } else if (this.mIdFloatClickSwitch.isChecked()) {
                    this.mIdFloatClickSwitch.setChecked(false);
                    FloatManager.hide(InitFloatBean.FloatType.hand);
                    return;
                } else {
                    this.mIdFloatClickSwitch.setChecked(true);
                    FloatManager.show(InitFloatBean.FloatType.hand);
                    return;
                }
            case R.id.id_float_click_layout_plus /*{ENCODED_INT: 2131296646}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    return;
                } else if (this.mIdFloatClickSwitchPlus.isChecked()) {
                    this.mIdFloatClickSwitchPlus.setChecked(false);
                    FloatManager.hide(InitFloatBean.FloatType.handPlus);
                    return;
                } else {
                    showHandDialog();
                    return;
                }
            case R.id.id_float_click_switch /*{ENCODED_INT: 2131296647}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    this.mIdFloatClickSwitch.setChecked(false);
                    return;
                } else if (this.mIdFloatClickSwitch.isChecked()) {
                    FloatManager.show(InitFloatBean.FloatType.hand);
                    return;
                } else {
                    FloatManager.hide(InitFloatBean.FloatType.hand);
                    return;
                }
            case R.id.id_float_click_switch_plus /*{ENCODED_INT: 2131296648}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    this.mIdFloatClickSwitchPlus.setChecked(false);
                    return;
                } else if (this.mIdFloatClickSwitchPlus.isChecked()) {
                    showHandDialog();
                    return;
                } else {
                    this.mIdFloatClickSwitchPlus.setChecked(false);
                    FloatManager.hide(InitFloatBean.FloatType.handPlus);
                    return;
                }
            case R.id.id_float_layout /*{ENCODED_INT: 2131296656}*/:
                if (this.mIdFloatSwitch.isChecked()) {
                    this.mIdFloatSwitch.setChecked(false);
                    FloatUtil.setShowFlow(this.mContext, false);
                    YYFloatButton.hide();
                } else {
                    this.mIdFloatSwitch.setChecked(true);
                    FloatUtil.setShowFlow(this.mContext, true);
                    YYFloatButton.show(MyApp.getContext());
                }
                if (NoticManager.getNoticValue(MyApp.getContext(), NoticEnum.FloatNotic)) {
                    NoticManager.getInstance().hide(NoticEnum.FloatNotic);
                    NoticManager.getInstance().show(NoticEnum.FloatNotic);
                    return;
                }
                return;
            case R.id.id_float_switch /*{ENCODED_INT: 2131296662}*/:
                if (this.mIdFloatSwitch.isChecked()) {
                    FloatUtil.setShowFlow(this.mContext, true);
                    YYFloatButton.show(MyApp.getContext());
                } else {
                    FloatUtil.setShowFlow(this.mContext, false);
                    YYFloatButton.hide();
                }
                if (NoticManager.getNoticValue(MyApp.getContext(), NoticEnum.FloatNotic)) {
                    NoticManager.getInstance().hide(NoticEnum.FloatNotic);
                    NoticManager.getInstance().show(NoticEnum.FloatNotic);
                    return;
                }
                return;
            case R.id.id_help /*{ENCODED_INT: 2131296687}*/:
                Intent intent = new Intent(this.mContext, WebViewActivity.class);
                this.mIntent = intent;
                intent.putExtra(SpFlag.k, "悬浮球绑定动作");
                this.mIntent.putExtra("url", "http://www.youyikeji.tech:8098/web/#/p/d54352586875a299b90d54aaa7ead091");
                this.mContext.startActivity(this.mIntent);
                return;
            case R.id.id_track_click_layout /*{ENCODED_INT: 2131296967}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    return;
                } else if (this.mIdTrackClickSwitch.isChecked()) {
                    this.mIdTrackClickSwitch.setChecked(false);
                    FloatManager.hide(InitFloatBean.FloatType.track);
                    return;
                } else {
                    this.mIdTrackClickSwitch.setChecked(true);
                    FloatManager.show(InitFloatBean.FloatType.track);
                    return;
                }
            case R.id.id_track_click_switch /*{ENCODED_INT: 2131296968}*/:
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(this.mContext);
                    this.mIdTrackClickSwitch.setChecked(false);
                    return;
                } else if (this.mIdTrackClickSwitch.isChecked()) {
                    FloatManager.show(InitFloatBean.FloatType.track);
                    return;
                } else {
                    FloatManager.hide(InitFloatBean.FloatType.track);
                    return;
                }
            default:
                return;
        }
    }

    /* access modifiers changed from: private */
    public class FlaotAdapter extends BaseAdapter {
        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        private FlaotAdapter() {
        }

        public int getCount() {
            return FloatFragment.this.mBindEnums.length;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(FloatFragment.this.mContext, R.layout.item_float_edit, null);
            ImageView imageView = (ImageView) inflate.findViewById(R.id.id_img);
            ImageView imageView2 = (ImageView) inflate.findViewById(R.id.id_del);
            ImageView imageView3 = (ImageView) inflate.findViewById(R.id.id_help);
            TextView textView = (TextView) inflate.findViewById(R.id.id_detail);
            final BindEnum bindEnum = FloatFragment.this.mBindEnums[i];
            ((TextView) inflate.findViewById(R.id.id_name)).setText(bindEnum.getName());
            String directData = DataUtil.getDirectData(FloatFragment.this.mContext, bindEnum.getType());
            if (TextUtils.isEmpty(directData)) {
                imageView2.setVisibility(View.GONE);
                textView.setText(R.string.not_edit);
                textView.setTextColor(-65536);
                if (bindEnum.isShowHelp()) {
                    imageView3.setVisibility(View.VISIBLE);
                    imageView3.setOnClickListener(new View.OnClickListener() {
                        /* class com.lmiot.xyclick.Bind.FloatFragment.FlaotAdapter.AnonymousClass1 */

                        public void onClick(View view) {
                            FloatFragment.this.showHelp(bindEnum);
                        }
                    });
                } else {
                    imageView3.setVisibility(View.GONE);
                }
            } else {
                imageView3.setVisibility(View.GONE);
                imageView2.setVisibility(View.VISIBLE);
                imageView2.setOnClickListener(new View.OnClickListener() {
                    /* class com.lmiot.xyclick.Bind.FloatFragment.FlaotAdapter.AnonymousClass2 */

                    public void onClick(View view) {
                        DataUtil.setDirectData(FloatFragment.this.mContext, bindEnum.getType(), "");
                        FlaotAdapter.this.notifyDataSetChanged();
                    }
                });
                textView.setText(((ActionBean) new ArrayGson().fromJson(directData, ActionBean.class)).getActionName());
                textView.setTextColor(FloatFragment.this.getResources().getColor(R.color.colorAccent));
            }
            Glide.with(FloatFragment.this.mContext).load(Integer.valueOf(bindEnum.getImg())).into(imageView);
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Bind.FloatFragment.FlaotAdapter.AnonymousClass3 */

                public void onClick(View view) {
                    FloatFragment.this.setFloatPosition(bindEnum);
                }
            });
            return inflate;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showHelp(BindEnum bindEnum) {
        final Dialog createBottomDailog = LayoutDialogUtil.createBottomDailog(this.mContext, R.layout.dialog_buttom_bind_help);
        TextView textView = (TextView) createBottomDailog.findViewById(R.id.bt_knnow);
        ImageView imageView = (ImageView) createBottomDailog.findViewById(R.id.id_img);
        ((TextView) createBottomDailog.findViewById(R.id.id_help_title)).setText(bindEnum.getName());
        ((TextView) createBottomDailog.findViewById(R.id.id_help_text)).setText(bindEnum.getDetail());
        if (bindEnum.getHelpImg() != 0) {
            imageView.setVisibility(View.VISIBLE);
            Glide.with(this.mContext).load(Integer.valueOf(bindEnum.getHelpImg())).into(imageView);
        } else {
            imageView.setVisibility(View.GONE);
        }
        textView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Bind.FloatFragment.AnonymousClass2 */

            public void onClick(View view) {
                createBottomDailog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setFloatPosition(BindEnum bindEnum) {
        Intent intent = new Intent(this.mContext, FloatEditActivity.class);
        this.mIntent = intent;
        intent.putExtra(SpFlag.k, bindEnum.getName());
        this.mIntent.putExtra("actionFlag", bindEnum.getType());
        startActivity(this.mIntent);
    }

    private void showHandDialog() {
        Dialog dialog = this.mDialog;
        if (dialog != null && dialog.isShowing()) {
            this.mDialog.dismiss();
        }
        this.mDialog = LayoutDialogUtil.createSysDailog(MyApp.getContext(), R.layout.dialog_random_click);
        if (Build.VERSION.SDK_INT >= 26) {
            this.mDialog.getWindow().setType(2038);
        } else {
            this.mDialog.getWindow().setType(2003);
        }
        final EditText editText = (EditText) this.mDialog.findViewById(R.id.hand_num);
        String str = DataUtil.getNowHandPlusNum(MyApp.getContext()) + "";
        editText.setText(str);
        editText.setSelection(str.length());
        ((TextView) this.mDialog.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Bind.FloatFragment.AnonymousClass3 */

            public void onClick(View view) {
                ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(editText.getWindowToken(), 0);
                FloatFragment.this.mDialog.dismiss();
                FloatFragment.this.mIdFloatClickSwitchPlus.setChecked(false);
                FloatManager.hide(InitFloatBean.FloatType.handPlus);
            }
        });
        ((TextView) this.mDialog.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Bind.FloatFragment.AnonymousClass4 */

            public void onClick(View view) {
                ((InputMethodManager) FloatFragment.this.mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(editText.getWindowToken(), 0);
                String trim = editText.getText().toString().trim();
                if (TextUtils.isEmpty(trim)) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    ToastUtil.warning("内容不能为空！");
                    return;
                }
                int parseInt = MathUtils.parseInt(trim);
                if (parseInt > 10) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    ToastUtil.warning("最多10个点击位置！");
                    return;
                }
                FloatFragment.this.mDialog.dismiss();
                for (int i = 0; i < 10; i++) {
                    FloatUtil.setShowFlowClickPlus(MyApp.getContext(), i, false);
                }
                DataUtil.setNowHandPlusNum(MyApp.getContext(), parseInt);
                for (int i2 = 0; i2 < parseInt; i2++) {
                    FloatUtil.setShowFlowClickPlus(MyApp.getContext(), i2, true);
                }
                if (FloatFragment.this.mIdFloatClickSwitchPlus != null) {
                    FloatFragment.this.mIdFloatClickSwitchPlus.setChecked(true);
                }
                FloatManager.show(InitFloatBean.FloatType.handPlus);
            }
        });
    }
}
